﻿@{
    Layout = null;  
}

@using MVC_Project.Model;

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>XXXX--管理系统</title>
    @Styles.Render("~/layui/css")
</head>

<body>
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <div class="layui-logo layui-hide-xs layui-bg-black">layout demo</div>
            <!-- 头部区域（可配合layui 已有的水平导航） -->
            <ul class="layui-nav layui-layout-left">
                <!-- 移动端显示 -->
                <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                    <i class="layui-icon layui-icon-spread-left"></i>
                </li>

                <li class="layui-nav-item layui-hide-xs"><a href="">nav 1</a></li>
                <li class="layui-nav-item layui-hide-xs"><a href="">nav 2</a></li>
                <li class="layui-nav-item layui-hide-xs"><a href="">nav 3</a></li>
                <li class="layui-nav-item">
                    <a href="javascript:;">nav groups</a>
                    <dl class="layui-nav-child">
                        <dd><a href="">menu 11</a></dd>
                        <dd><a href="">menu 22</a></dd>
                        <dd><a href="">menu 33</a></dd>
                    </dl>
                </li>
            </ul>
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item layui-hide layui-show-md-inline-block">
                    <a href="javascript:;">
                        <img id="headimg" src="@Session["headimg"]" class="layui-nav-img">
                        @Session["name"]
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:OpenTab(15,'个人信息','','Manage','Personal');">个人中心</a></dd>
                        <dd><a href="">设置</a></dd>
                        <dd><a href="/Sign/Out">退出</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
                    <a href="javascript:;">
                        <i class="layui-icon layui-icon-more-vertical"></i>
                    </a>
                </li>
            </ul>
        </div>

        <div class="layui-side layui-bg-black">
            <div class="layui-side-scroll">
                <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                <ul id="menusbox" class="layui-nav layui-nav-tree" lay-filter="test">
                    @{
                        foreach (var m in ViewBag.menus as List<Menus>)
                        {
                            //一级菜单
                            if (m.parentID == 0)
                            {
                                <li class="layui-nav-item">
                                    <a href="javascript:;">@m.menuName</a>
                                    <dl class="layui-nav-child">

                                        @{
                                            foreach (var mm in ViewBag.menus as List<Menus>)
                                            {
                                                if (mm.parentID == m.menuID)
                                                {
                                                    <dd lay-id="@mm.menuID"><a href="javascript:OpenTab(@mm.menuID,'@mm.menuName','@mm.area','@mm.controller','@mm.action');">@mm.menuName</a></dd>
                                                }

                                            }
                                        }

                                    </dl>
                                </li>
                            }

                        }
                    }


                </ul>

            </div>
        </div>

        <div class="layui-body">
            <!-- 内容主体区域 -->
            <div style="padding: 15px;">
                <div class="layui-tab " lay-allowClose="true" lay-filter="page_tab" style="margin:0px;">
                    <ul class="layui-tab-title">
                    </ul>
                    <div class="layui-tab-content">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-footer">
            <!-- 底部固定区域 -->
            底部固定区域
        </div>
    </div>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/layui")
    <script>
        //JS
        var element;
        layui.use(['element', 'layer', 'util'], function () {
                element = layui.element
                , layer = layui.layer
                , util = layui.util
                , $ = layui.$;

            //头部事件
            util.event('lay-header-event', {
                //左侧菜单事件
                menuLeft: function (othis) {
                    layer.msg('展开左侧菜单的操作', { icon: 0 });
                }
                , menuRight: function () {
                    layer.open({
                        type: 1
                        , content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
                        , area: ['260px', '100%']
                        , offset: 'rt' //右上角
                        , anim: 5
                        , shadeClose: true
                    });
                }
            });

            //Tab  切换事件
            element.on('tab(page_tab)', function (data) {
                let myiframe = $(data.elem).find(".layui-show iframe");
                if (myiframe.attr('src').length < 1) {
                    var index = layer.load();
                    //强制切换刷新
                    myiframe.attr('src', myiframe.data('url'));
                }
                myiframe.on("load", function () {
                    layer.close(index);
                })

                //获取当前Tab页的 layid
                let layid = $(this).attr("lay-id");

                //切换左边菜单选中
                $("#menusbox dd").each(function (i, o) {
                    if ($(o).attr("lay-id") == layid) {
                        $(o).addClass("layui-this").siblings().removeClass("layui-this").parent().parent().addClass("layui-nav-itemed")
                            .siblings().removeClass("layui-nav-itemed").find("dd").removeClass("layui-this");

                    }
                })
            });


            OpenTab(16, "用户管理", "System", "Users", "Index");
        });

        //打开选项卡
        function OpenTab(id, name, area, contro, action) {
            var isData = false; //记录是否已经存在 Tab页
            $.each($(".layui-tab-title li[lay-id]"), function () {
                if ($(this).attr("lay-id") == id) {
                    isData = true;
                }
            })
            if (!isData) {  //没有就添加一个新Tab页
                //添加新的选项卡
                let pathurl = "";
                pathurl += area.length > 0 ? "/" + area : "";
                pathurl += "/" + contro + "/" + action;

                element.tabAdd('page_tab', {
                    title: name
                    , content: '<iframe data-frameid="' + id + '" data-url="' + pathurl + '" scrolling="auto" frameborder="0" src style="width:100%;height:90%;"></iframe>'
                    , id: id
                });
                FrameWH();
            }
            //切换到选项卡
            element.tabChange("page_tab", id);
        }

        //主内容 iframe 高度适应
        function FrameWH() {
            var h = $(".layui-body")[0].scrollHeight - $(".layui-tab-title")[0].scrollHeight - 20 - 2;
            //console.log(h);
            $("iframe").css("height", h + "px");
        }

        $(window).resize(function () {
            FrameWH();
        })

        //删除当前选项卡
        function DelTab() {
            var layid = $(".layui-tab .layui-this").attr("lay-id");
            element.tabDelete("page_tab", layid);
        }


    </script>
</body>

</html>
